<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
    <title>安装转介</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #F3F3F3;
        }

        .img {
            width: 100%;
            height: 25vh;
        }

        .card {
            width: 95%;
            border-radius: 15px;
            background-color: #fff;
            position: absolute;
            left: calc((100% - 95%) / 2);
            z-index: 2;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-shadow: 0px 2px 15px 1px #dcdcdc;
            top: -40px;
        }

        .card>h4 {
            color: #F96841;
            margin: 3vh 0 1.5vh 0;
            letter-spacing: 1px;
        }

        .p1 {
            width: 45px;
            border-bottom: 1px solid #F96841;
            margin-bottom: 15px;
        }

        .p2 {
            font-size: 13px;
            margin-bottom: 20px;
        }

        .card_input {
            width: 80%;
            display: flex;
            margin: 0 auto 25px auto;
        }

        .card_input>div {
            letter-spacing: 1px;
            line-height: 30px;
            font-size: 1rem;
        }

        .card_input>input {
            line-height: 30px;
            margin-left: 20px;
            border: 0;
            border-radius: 0;
            outline: none;
            font-size: 1rem;
            width: 50%;
        }

        .confirm {
            width: 60%;
            height: 35px;
            border-radius: 25px;
            background: #F96841;
            border: 0;
            color: #fff;
            position: absolute;
            left: calc((100% - 60%)/2);
            outline: none;
            top: 375px;
        }

        .card-img {
            position: relative;
        }
    </style>
</head>

<body>
    <div class="contain">
        <div class="head">
            <img class="img" src="./image/head3.png"></img>
        </div>
        <div class="card-img">
            <div class="card">
                <h4>转介信息</h4>
                <p class="p1"></p>
                <p class="p2">请根据提示填写信息, 我们将在48小时内电话回复</p>
                <div class="card_input">
                    <div>
                        <text>姓名:</text>
                    </div>
                    <input type="text" id="name" class="name" placeholder="请输入姓名">
                </div>
                <div class="card_input">
                    <div>
                        <text>电话:</text>
                    </div>
                    <input type="text" id="phone" class="phone" placeholder="请输入电话">
                </div>
                <div class="card_input">
                    <div>
                        <text>地区:</text>
                    </div>
                    <input type="text" id="area" class="area" placeholder="请输入地区">
                </div>
                <div class="card_input">
                    <div>
                        <text>物业联系人:</text>
                    </div>
                    <input type="text" id="person" placeholder="请输入联系人">
                </div>
                <div class="card_input">
                    <div>
                        <text>物业电话:</text>
                    </div>
                    <input type="text" id="tel" placeholder="请输入物业电话">
                </div>
            </div>
            <button class="confirm">提交</button>
        </div>
    </div>
</body>
<script src="js/jquery-3.5.1.min.js"></script>
<script>
    $(() => {
        let u = navigator.userAgent
        let user_id = getUrldata('Uid')
        let rugle = /([^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n])|(\s)/g
        let url_ = 'partner.html?Uid=' + user_id
        // 判断ios
        let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
        // 判断android
        let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
        //判断微信
        function isWeiXin() {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                return true; // 是微信端
            } else {
                return false;
            }
        }

        // 统一弹框
        function info_alert(param) {
            if (isWeiXin()) {
                (() => {
                    window.alert = function (name) {
                        var iframe = document.createElement("IFRAME");
                        iframe.style.display = "none";
                        iframe.setAttribute("src", 'data:text/plain');
                        document.documentElement.appendChild(iframe);
                        window.frames[0].window.alert(name);
                        iframe.parentNode.removeChild(iframe);
                    }
                })()
                alert(param)
                return
            }
            if (isiOS) {
                window.webkit.messageHandlers.showAlert.postMessage(param)
                return
            }
            if (isAndroid) {
                window.TiantianCharge_Android.showAlert(param)
                return
            }
        }

        // 切割区域
        function reg(zone) {
            let zone_arr = zone.split('-')
            return zone_arr
        }

        // 返回页面防止刷新
        $('.confirm').click(() => {
            let name = $('#name').val()
            let phone = $('#phone').val()
            let area = $('#area').val()
            let tel = $('#tel').val()
            let person = $('#person').val()
            if (name == '' || phone == '' || tel == '' || person == '' || area == '') {
                info_alert('请输入内容')
            } else if (/^1[3456789]\d{9}$/.test(phone) == false) {
                info_alert('电话有误,请重新输入')
            } else if (/^1[3456789]\d{9}$/.test(tel) == false) {
                info_alert('物业电话有误,请重新输入')
            } else if (rugle.test(name) || rugle.test(phone) || rugle.test(tel) || rugle.test(person) || rugle.test(area)) {
                info_alert('不支持此类型内容')
            } else {
                $.ajax({
                    type: 'POST',
                    data: {
                        userid_locked: user_id,
                    },
                    url: 'https://api.cd1a.cn/index.php/activity/Trans/ispartner',
                    dataType: 'json',
                    async: true
                }).then(res => {
                    console.log(res)
                    if (res.code == '2') {
                        // 不是合伙人
                        if (isWeiXin()) {
                            (() => {
                                window.alert = function (name) {
                                    var iframe = document.createElement("IFRAME");
                                    iframe.style.display = "none";
                                    iframe.setAttribute("src", 'data:text/plain');
                                    document.documentElement.appendChild(iframe);
                                    window.frames[0].window.alert(name);
                                    iframe.parentNode.removeChild(iframe);
                                }
                            })()
                            alert(res.msg)
                            window.location.replace(url_)
                        }
                        if (isiOS) {
                            window.webkit.messageHandlers.showAlert.postMessage(res.msg)
                            window.location.replace(url_)
                        }
                        if (isAndroid) {
                            window.TiantianCharge_Android.showAlert(res.msg)
                            window.location.replace(url_)
                        }
                    } else if (res.code == '1') {
                        // 合伙人
                        $.ajax({
                            url: 'https://api.cd1a.cn/index.php/activity/Trans/introduce',
                            data: {
                                userid_locked: user_id,
                                name: name,
                                tel: tel,
                                region: area,
                                phone: phone,
                                contacts: person
                            },
                            type: 'POST',
                            dataType: 'json',
                            async: true,
                            success: function (res) {
                                console.log(res)
                                // 录入成功
                                if (res.code == '1') {
                                    if (isWeiXin()) {
                                        (() => {
                                            window.alert = function (name) {
                                                var iframe = document.createElement("IFRAME");
                                                iframe.style.display = "none";
                                                iframe.setAttribute("src", 'data:text/plain');
                                                document.documentElement.appendChild(iframe);
                                                window.frames[0].window.alert(name);
                                                iframe.parentNode.removeChild(iframe);
                                            }
                                        })()
                                        alert('录入成功')
                                        if (window.__wxjs_environment === 'miniprogram') {
                                            wx.miniProgram.reLaunch({
                                                url: '/pages/personalCenter/personalCenter'
                                            })
                                        }
                                    }
                                    if (isiOS) {
                                        window.webkit.messageHandlers.goBack.postMessage('录入成功')
                                    }
                                    if (isAndroid) {
                                        window.TiantianCharge_Android.showAlert('录入成功')
                                        window.TiantianCharge_Android.closeH5()
                                    }
                                } else {
                                    info_alert(res.msg)
                                }
                            }
                        })
                    } else {
                        // 其他
                        info_alert(res.msg)
                    }
                })
            }
        })

        // 获取用户id
        function getUrldata(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
            var r = window.location.search.substr(1).match(reg)
            if (r != null) return decodeURI(r[2])
            return null
        }
    })
</script>

</html>